package edu.umn.se.trap.logicChecker;

import java.util.Observable;
import java.util.Observer;

import edu.umn.se.trap.Form;
import edu.umn.se.trap.TravelDetails;
import edu.umn.se.trap.exceptions.SyntaxException;

public class CheckSyntaxDate implements Observer {
    
    @Override
    /**
     * Update to check for the correct dates and times for departure and arrival
     */
    public void update(Observable o, Object arg) 
    {
        LogicChecker l1 = (LogicChecker) o;
        Form form = (Form) arg;
        
        TravelDetails travel = form.getTravelDetails();
        int depDate = travel.getDepartureDate();
        int depTime = travel.getDepartureTime();
        int arrDate = travel.getArrivalDate();
        int arrTime = travel.getArrivalTime();
        
        if (arrDate > depDate)
        {
            if (arrTime < depTime)
            {
                l1.setException(new SyntaxException("Error date time"));
            }
        }
        else
        {
            l1.setException(new SyntaxException("Error in dates"));
        }
    }
}